package com.ddc.study.base;

import android.os.Bundle;

import androidx.annotation.Nullable;

/**
 * Created on 2018/5/21.
 *
 * @author lshun
 * @version 1.0
 */
public abstract class MvpFragment<V extends BaseView, T extends BasePresenter<V>>
        extends BaseFragment implements BaseView {
    protected T mPresenter;

    protected abstract T createPresenter();

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mPresenter = createPresenter();
        mPresenter.attachView((V) this);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mPresenter.detachView();
    }

    @Override
    public void runOnUIThread(Runnable runnable) {
        if (getActivity() != null) {
            getActivity().runOnUiThread(runnable);
        }
    }

    @Override
    public final String getStringValue(int resId) {
        return getString(resId);
    }
}
